<!DOCTYPE html>
<html lang="zh-CN">
<head>


    <meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=0.5, maximum-scale=2.0, user-scalable=yes" />
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="renderer" content="webkit">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <title>蓝牙测试</title>
    　　<link rel="apple-touch-icon" href="/apple-touch-icon.png（180*180）">
    　　<link rel="icon" href="/favicon.ico（32*32）">
    <!--<script src=”//api.html5media.info/1.1.8/html5media.min.js></script>-->
    <script src="//cdn.jsdelivr.net/npm/eruda"></script>
    <script>eruda.init();</script>

    <script>

        function openBluetoothAdapterJS(){
            var err= window.hilink.openBluetoothAdapter();
            alert("openBluetoothAdapterJS "+err);
        }

        function closeBluetoothAdapterJS(){
            var err= window.hilink.closeBluetoothAdapter();
            alert("closeBluetoothAdapterJS "+err);
        }

        function startBluetoothDevicesDiscoveryJS(){
            var services = ['0000FFE0-0000-1000-8000-00805F9B34FB'];
            var allowDuplicatesKey = true;
            var interval = "10";
            var retCode = window.hilink.startBluetoothDevicesDiscovery(services, allowDuplicatesKey, interval);
            alert("javascript:retCode ="+retCode);

        }

        function stopBluetoothDevicesDiscoveryJS(){
            var retCode = window.hilink.stopBluetoothDevicesDiscovery();
            alert("javascript:retCode ="+retCode);
        }

        function createBLEConnectionJS(){
//            var deviceId = "C7:EC:BB:D8:51:3C";
            var deviceId = 'C8:FD:19:58:BC:10';
            var retCode = window.hilink.createBLEConnection(deviceId);
            alert("javascript:retCode ="+retCode);
        }

        function closeBLEConnectionJS(){
            var retCode = window.hilink.closeBLEConnection();
            alert("javascript:retCode ="+retCode);
        }

        function getConnectedBluetoothDevicesJS(){
            var retCode = window.hilink.getConnectedBluetoothDevices("0000ffe1-0000-1000-8000-00805f9b34fb","getConnectedBluetoothDevicesCall");
            alert("javascript:retCode ="+retCode);
        }

        function writeBLECharacteristicValueJS(){
            var deviceId = "'C8:FD:19:58:BC:10'";
            var serviceId = "0000ffe0-0000-1000-8000-00805f9b34fb";
            var characteristicId = "0000ffe1-0000-1000-8000-00805f9b34fb";

            var buf = [1,3,0,5,0,30,100,13];
            var data = JSON.stringify(buf);
            var callback="onCharacterWrite";
            var retCode =window.hilink.writeBLECharacteristicValue(deviceId, serviceId, characteristicId, data,callback);
            alert("javascript:retCode ="+retCode);
        }

        function onCharacterWrite(re){
            alert("aaa"+re);
            readBLECharacteristicValueJS()
        }

        function notifyBLECharacteristicValueChangeJS(){
            var deviceId = "C8:FD:19:58:BC:10";
            var serviceId = "0000ffe0-0000-1000-8000-00805f9b34fb";
            var characteristicId = "0000ffe1-0000-1000-8000-00805f9b34fb";
            var data =true;
            var retCode =window.hilink.notifyBLECharacteristicValueChange(deviceId, serviceId, characteristicId, data);
            alert("javascript:retCode ="+retCode);
        }

        function readBLECharacteristicValueJS(){
            var deviceId = "C8:FD:19:58:BC:10";
            var serviceId = "0000ffe0-0000-1000-8000-00805f9b34fb";
            var characteristicId = "0000ffe1-0000-1000-8000-00805f9b34fb";
            var callback="onCharacterRead"
            var data = window.hilink.readBLECharacteristicValue(deviceId, serviceId, characteristicId,callback);
            alert("javascript:data ="+data);
        }

        function onCharacterRead(re){
            alert("bbb"+re);
        }
        window.onBluetoothDeviceFound = onBluetoothDeviceFound;
        function onReadBLECharacteristicValue(res){
            alert(res)
        }

        function bluetoothAvailableJS(){
            window.hilink.bluetoothAvailable();
        }

        function checkstateJS(){
            window.hilink.checkstate();
        }

        function getBundleDeviceJS(){
            window.hilink.getBundleDevice();
        }

        function sendDataJS(){
            window.hilink.sendData();
        }

        function getBluetoothDevicesJS(res){
            console.log("res:::",res)
            window.hilink.getBluetoothDevices(res);
        }
        function getBluetoothDevices(res){
            alert(res)
        }
        window.getBluetoothDevices = getBluetoothDevices;
        function onBluetoothDeviceFoundJS(res){
            var retCode = window.hilink.onBluetoothDeviceFound(res);
            alert("javascript:retCode ="+retCode);
        }
        window.onBluetoothDeviceFound = onBluetoothDeviceFound;
        function onBluetoothDeviceFound(res){
            alert(res+'aaa')
        }

        window.getBluetoothDevices = getBluetoothDevices;
        function getSystemInfoSyncJS(res){
            window.hilink.getSystemInfoSync(res);
        }
        window.getSystemInfoSync = getSystemInfoSync;
        function getSystemInfoSync(res){
            alert(res)
        }
    </script>

    <script type="text/javascript">

        //回调函数
        function openBluetoothAdapterCallBack(str){
            alert("javascript:"+str);
        }

        function closeBluetoothAdapterCallBack(str){
            alert("javascript:"+str);
        }

        function stopBluetoothDevicesDiscoveryCallBack(str){
            alert("javascript:"+str);
        }

//        function onCharacterWrite(re){
//            alert("aaa"+re);
//        }

        function getConnectedBluetoothDevicesCall(str){
            alert("aaccc"+str);
        }
    </script>

</head>


<body>
<div style="position: absolute; left: 50px; top: 20px; ">
    <div style="margin-top: 10px;border: 1px  solid royalblue">
        <div style="background-color: white;margin-top: 10px;">
            <button id='btn00' type='submit' onclick='startBluetoothDevicesDiscoveryJS()'>扫描设备startBluetoothDevicesDiscoveryJS</button>
        </div>
        <br>
        <code>
            function startBluetoothDevicesDiscoveryJS(){   <br>
                var services = ['0000ffe0-0000-1000-8000-00805f9b34fb'];   <br>
                var allowDuplicatesKey = true;   <br>
                var interval = "10";   <br>
                var retCode = window.hilink.startBluetoothDevicesDiscovery(services, allowDuplicatesKey, interval);   <br>
                alert("javascript:retCode ="+retCode);   <br>
            <br>
            }
        </code>
    </div>

    <br>
    <button id='btn20' type='submit' onclick='getConnectedBluetoothDevicesJS()'>getConnectedBluetoothDevices</button>
    <br>

    <br>
    <button id='btn3' type='submit' onclick='openBluetoothAdapterJS()'>openBluetoothAdapter</button>
    <br>

    <br>
    <button id='btn4' type='submit' onclick='closeBluetoothAdapterJS()'>closeBluetoothAdapter</button>
    <br>

    <br>
    <button id='btn5' type='submit' onclick="startBluetoothDevicesDiscoveryJS()">startBluetoothDevicesDiscovery</button>
    <br>
    <br>
    <button id='btn10' type='submit' onclick="onBluetoothDeviceFoundJS('onBluetoothDeviceFound')">onBluetoothDeviceFound</button>
    <br>
    <br>
    <button id='btn6' type='submit' onclick="stopBluetoothDevicesDiscoveryJS()">stopBluetoothDevicesDiscovery</button>
    <br>
    <br>
    <button id='btn15' type='submit' onclick="createBLEConnectionJS()">createBLEConnection</button>
    <br>

    <br>
    <button id='btn11' type='submit' onclick="closeBLEConnectionJS()">closeBLEConnection</button>
    <br>


    <br>
    <button id='btn9' type='submit' onclick="writeBLECharacteristicValueJS()">writeBLECharacteristicValue</button>
    <br>

    <br>
    <button id='btn13' type='submit' onclick="readBLECharacteristicValueJS()">readBLECharacteristicValue</button>
    <br>

    <br>
    <button id='btn18' type='submit' onclick="notifyBLECharacteristicValueChangeJS()">notifyBLECharacteristicValueChange</button>
    <br>
    <br>
    <button id='btn19' type='submit' onclick="getSystemInfoSyncJS('getSystemInfoSync')">getSystemInfoSync</button>
    <br>
    <!--<hr>-->


    <!--<br>-->
    <!--<button id='btn1' class='btnclass' type='submit'  onclick='bluetoothAvailableJS()'>检查蓝牙是否可用</button>-->
    <!--<br>-->

    <!--<br>-->
    <!--<button id='btn2' class='btnclass' type='submit'  onclick="checkstateJS()">检查当前蓝牙状态</button>-->
    <!--<br>-->


    <!--<br>-->
    <!--<button id='btn7' type='submit' onclick="getBundleDeviceJS()">H5获取已经绑定的设备,再回调到android中</button>-->
    <!--<br>-->

    <!--<br>-->
    <!--<button id='btn8' type='submit' onclick="sendDataJS()">获取h5数据</button>-->
    <!--<br>-->


    <br>
    <button id='btn12' type='submit' onclick="getBluetoothDevicesJS('getBluetoothDevices')">getBluetoothDevices</button>
    <br>

    <script>
        function getCurrentUnregisteredDeviceJS(res){
            var retCode = window.hilink.getCurrentUnregisteredDevice(res);
            alert("javascript:retCode ="+retCode);
        }
        function getCurrentUnregisteredDevice(res){
            alert(res+'555')
        }
    </script>
    <br>
    <button id='btn1344' type='submit' onclick="getCurrentUnregisteredDeviceJS('getCurrentUnregisteredDevice')">getCurrentUnregisteredDevice</button>
    <br>

    <br>
</div>




<div style="position: absolute; left: 50px; top: 750px; bottom: 150px">
    <input id = "name_input" class = "inputStyle" type="text"/>
    <a class = "rect" onclick="sendInfoToJava()">JS调用Java</a>
    <br>
</div>
<br>


</body>
</html>